package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/25/20 11:10 AM
 */
public class 其他数都出现k次的数组中找只出现一次的数 {

    public int findCountOne(int[] nums, int k) {

        // k 次
        int eor = 0;

        for (int num : nums) {

            eor = baseKAdd(eor,num,k);
        }

        return eor;
    }

    private int baseKAdd(int sum,int num, int k) {

        // 30,30,30,9,1,1,1,4,4,4
        int b = 1;
        int everySum = 0;
        while (sum  > 0 || num > 0) {

            int bit = num % k;
            int sBit = sum % k;

            // 把结果换成10进制
            everySum += ((bit + sBit) % k) * b;
            num /= k;
            sum /= k;
            b*=k;
        }

        return everySum;
    }
}
